package com.wz.jiangsu.main.huiwenshu;


import org.assertj.core.util.Lists;

import java.util.ArrayList;
import java.util.List;

public class TestFenZu {
    public static void main(String[] args) {
        List<Integer> list = Lists.newArrayList(1, 2, 3, 11, 22, 55, 11);
        int group = 3;
        List<List<Integer>> lists  = getListsByGroup(list,group);
    }

    private static List<List<Integer>> getListsByGroup(List<Integer> list, int group) {

        List<List<Integer>> lists = new ArrayList<>();
        int size = list.size();
        int base = size / group;
        int remain = size % group;
        int start = 0;
        for (int i = 0; i < group; i++) {
            int end = start + base + (i< remain ? 1 : 0);
            List<Integer> list1 = list.subList(start, end);
            lists.add(list1);
            start = end;
        }
        return lists;
    }
}
